<?php
class Member_model extends MY_Model {

    function __construct(){
        parent::__construct();
        $this->tbl_name = 'edm_orders';
    }

    function regist($member){
		if($this->in('member',array('nname'=>$member['nname']))) return -1;
    	if($this->in('member',array('email'=>$member['email']))) return -2;

    	$id = $this->save('member',$member);
		
		if(!empty($member['invitor'])){
		    $this->cm->insert('follow',array('uid'=>$id,'fid'=>$member['invitor']));
		    $this->cm->insert('follow',array('fid'=>$id,'uid'=>$member['invitor']));
		}
		
		return 1;

    }
    
    function login($uname,$upass){
        $superadmin = $this->get_kv('superadmin');

        if($uname == $superadmin['uname'] && md5($upass) == $superadmin['upass'] ){
            $_SESSION['loginer'] = $superadmin;
    		return true;
        } 

    	return false;
    }
    
    function is_login(){
        if(!empty($_SESSION['loginer'])){
            $uname = $_SESSION['loginer']['uname'];
            $upass = $_SESSION['loginer']['upass'];

            $superadmin = $this->get_kv('superadmin');
            if($uname == $superadmin['uname'] && $upass == $superadmin['upass'] ){
                return true;
            } 
        }        
        return false;
    }
    
}